#pragma once

#include "OccurrenceSpecification.h"

#include "GeneralOrdering.h"
#include "Lifeline.h"

namespace uml {

OccurrenceSpecification::OccurrenceSpecification(const QString& umlType)
    : NamedElement(umlType) {}

void OccurrenceSpecification::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    NamedElement::fromJson(json, errorList);
    InteractionFragment::fromJson(json, errorList);
    covered_ = JsonSerializable::create<Lifeline>(json.value("covered"), errorList);

    JsonSerializable::fromJsonArray(toAfters_, "toAfters", json, errorList);
    JsonSerializable::fromJsonArray(toBefores_, "toBefores", json, errorList);
}

void OccurrenceSpecification::toJson(QJsonObject& json) {
    NamedElement::toJson(json);
    InteractionFragment::toJson(json);
    if (covered_) {
        QJsonObject covered_json;
        covered_->toJson(covered_json);
        json.insert("covered", covered_json);
    }
    JsonSerializable::toJsonArray(toAfters_, "toAfters", json);
    JsonSerializable::toJsonArray(toBefores_, "toBefores", json);
}

/// <summary>
/// covered getter
/// References the Lifeline on which the OccurrenceSpecification appears.
/// </summary>
shared_ptr<Lifeline> OccurrenceSpecification::covered() const {
    return covered_;
}

/// <summary>
/// covered setter
/// References the Lifeline on which the OccurrenceSpecification appears.
/// </summary>
void OccurrenceSpecification::setCovered(shared_ptr<Lifeline> value) {
    covered_ = value;
}

/// <summary>
/// toAfters getter
/// References the GeneralOrderings that specify EventOcurrences that must occur
/// after this OccurrenceSpecification.
/// </summary>
vector<shared_ptr<GeneralOrdering>>& OccurrenceSpecification::toAfters() {
    return toAfters_;
}

/// <summary>
/// toBefores getter
/// References the GeneralOrderings that specify EventOcurrences that must occur
/// before this OccurrenceSpecification.
/// </summary>
vector<shared_ptr<GeneralOrdering>>& OccurrenceSpecification::toBefores() {
    return toBefores_;
}

} // namespace uml
